<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：因为只能一天买入一天卖出，所以只需要找出最低成本和后面的最高价格就行
      */
      var maxProfit = function (prices) {
        let profit = 0
        let cover = prices[0]
        for (let i = 0; i < prices.length; i++) {
          cover = Math.min(cover, prices[i])
          profit = Math.max(profit, prices[i] - cover)
        }
        return profit
      }
    </script>
  </body>
</html>
